﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 提交管理平台V1
{
    public partial class frmConfig : Form
    {
        UserInfo ui;
        string strTableName;

        public frmConfig(UserInfo tmpui,string strTmpTableName)
        {
            InitializeComponent();
            ui = tmpui;
            strTableName = strTmpTableName;
        }

        private void frmConfig_Load(object sender, EventArgs e)
        {
            iniInterface();
        }

        private void iniInterface()
        {
            //初始化下拉列表框
            cmbTemplateName.Items.Clear();
            for (int i = 1; i <= 10; i++)
            {
                cmbTemplateName.Items.Add("导出模板" + i.ToString());
            }
            cmbTemplateName.SelectedIndex = 0;
            txtFields.Text = ui.GetUserSetting("字段设置");
            txtHideFields.Text = ui.GetUserSetting("隐藏字段设置");
            nudMaxRecordCount.Value = GeneralTools.GetInt(ui.GetUserSetting("最大记录条数"), 1);
            nudFontSize.Value = GeneralTools.GetInt(ui.GetUserSetting("字号"), 10);
            txtValue_kpr.Text = ui.GetUserSetting("开票人");
            txtValue_wbzy.Text = ui.GetUserSetting("外包装包装员");
        }

        private void cmbTemplateName_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtTemplate.Text = ui.GetUserSetting(cmbTemplateName.Text);
        }

        private void btnConfig_field_Click(object sender, EventArgs e)
        {
            string strTmpSetting=txtFields.Text;
            if (frmFieldsSettings.Show(ref strTmpSetting,strTableName , false) == DialogResult.OK)
            {
                txtFields.Text = strTmpSetting;
                if (ui.UpdateUserSetting("字段设置", txtFields.Text))
                {
                    GeneralTools.ShowInfoMsg("设置保存成功！");
                }
                else
                {
                    GeneralTools.ShowErrorMsg("设置保存失败！");
                }
            }
        }

        private void btnConfig_hidefields_Click(object sender, EventArgs e)
        {
            string strTmpSetting = txtHideFields.Text;
            if (frmHideFieldsSettings.Show(ref strTmpSetting, ui) == DialogResult.OK)
            {
                txtHideFields .Text =strTmpSetting ;
                if (ui.UpdateUserSetting("隐藏字段设置", txtHideFields.Text))
                {
                    GeneralTools.ShowInfoMsg("设置保存成功！");
                }
                else
                {
                    GeneralTools.ShowErrorMsg("设置保存失败！");
                }
            }
        }

        private void btnConfig_template_Click(object sender, EventArgs e)
        {
            string strTmpSetting = txtTemplate.Text;
            if (frmFieldsSettings.Show(ref strTmpSetting,strTableName  , true) == DialogResult.OK)
            {
                txtTemplate.Text=strTmpSetting ;
                if (ui.UpdateUserSetting(cmbTemplateName.Text, txtTemplate.Text))
                {
                    GeneralTools.ShowInfoMsg("设置保存成功！");
                }
                else
                {
                    GeneralTools.ShowErrorMsg("设置保存失败！");
                }
            }
        }

        private void btnConfig_maxrecord_Click(object sender, EventArgs e)
        {
            ui.UpdateUserSetting("最大记录条数", nudMaxRecordCount.Value.ToString());
        }

        private void btnConfig_fontsize_Click(object sender, EventArgs e)
        {
            ui.UpdateUserSetting("字号", nudFontSize.Value.ToString());
        }

        private void btnConfig_wbzy_Click(object sender, EventArgs e)
        {
            ui.UpdateUserSetting("外包装包装员", txtValue_wbzy.Text);
        }

        private void btnConfig_kpr_Click(object sender, EventArgs e)
        {
            ui.UpdateUserSetting("开票人", txtValue_kpr.Text);
        }

        private void btnConfig_ERP_Click(object sender, EventArgs e)
        {
            ui.UpdateUserSetting("ERP用户名", txtValue_ERP.Text.Trim ());
        }
    }
}